﻿/*
 * Created by SharpDevelop.
 * User: aleva3
 * Date: 11/7/2012
 * Time: 15:11
 */
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;

namespace Froude_and_Wt_calculation
{
	/// <summary>
	/// Description of MainForm.
	/// </summary>
	public partial class MainForm : Form
	{
		public MainForm()
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
			
			//
			// TODO: Add constructor code after the InitializeComponent() call.
			//
		}
	
		void Button1Click(object sender, EventArgs e)  //Calculated parameters
		{
			double V, D, delta, Wt, m, t;
			double Cp, Cm;			
			FroudeCalculator Fr;
			
			m=1;
			
			Velocity speedFlag = Velocity.MetersPerSecond;
			if (radioButton3.Checked==true)
			{
				speedFlag = Velocity.Knot;
			}
			else
			{
				if (radioButton4.Checked==true)
					speedFlag = Velocity.KilomesterPerHour;
			}
						
			Fr = new FroudeCalculator( Convert.ToDouble(textBox6.Text), 
			                           Convert.ToDouble(textBox4.Text),
 			                           speedFlag);
			
			V  = Convert.ToDouble(textBox1.Text);
			D  = Convert.ToDouble(textBox2.Text);
			Cp = Convert.ToDouble(textBox3.Text);
			Cm = Convert.ToDouble(textBox9.Text);
			
			delta = Cp*Cm;
			
			if (radioButton2.Checked==true)
			{
				m=2;
			}
			
			if (Fr.Value < 0.2)
			{
				Wt=0.165*Math.Pow(delta,m)*Math.Sqrt(Math.Pow(V,1/3.0)/D);
			}
			else
			{
				Wt=0.165*Math.Pow(delta,m)*Math.Sqrt(Math.Pow(V,1/3.0)/D)-0.1*(Fr.Value-0.2);
			}
			
			if (m==1)
			{
				t=0.7*Wt;
			}
			else
			{
				if (radioButton6.Checked==true)
				{
					t=0.25*Wt+0.14;
				}
				else
				{
					t=0.7*Wt+0.06;
				}
			}
			
			textBox8.Text=Convert.ToString(t);
			textBox7.Text=Convert.ToString(Wt);			
			textBox5.Text=Convert.ToString(Fr.Value);
		}		
		
		void RadioButton2CheckedChanged(object sender, EventArgs e)
		{
			if (radioButton2.Checked==true)
			{
				groupBox2.Enabled=true;
			}
			else
			{
				groupBox2.Enabled=false;
			}
		}		
	}
}
